home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.11 Nov 88 / fast rotate source / rotate.a changes < prev    next >
Encoding:
Text File  |  1988-05-18  |  6.0 KB  |  238 lines  |  [TEXT/MPS ]

  1. ; Following is the changed portion of ROTATE.A:
  2.     lea    localVars,a0
  3.  
  4.     ; Synchronize with the TickCount rollover.
  5.     move.l    ticks, d0            ; get the time
  6. @1    cmp.l    ticks, d0            ; changed yet?
  7.     beq.s    @1                    ; nope: loop
  8.  
  9.     ; Strobe the starting time.
  10.     move.l    ticks, startTime-localVars(a0) ; save starting time, in ticks
  11.  
  12. ;
  13. ; initialize d0 to contain the pointer to the srcMap
  14. ;
  15.     move.w    rowbytes(a1),d0        ; get rowbytes of srcMap
  16.     
  17. ;
  18. ; get regs pointing to bits
  19. ;
  20.     move.l    (a1),a1                ; a1 pts to BITS of src bitMap    
  21.     move.l    (a2),a3                ; a3 pts to BITS of dest bitMap
  22.  
  23. ; compute the lower left corner of the destMap - this maps to the upper left
  24. ; corner of the srcMap and will be used as base from which to offset into
  25. ; the dest map when we need to set a bit
  26. ;
  27.     clr.l    d1                    ; clear d1 
  28.     move.w    d0,d1                ; load rowBytes of srcMap
  29.                                 ; (rowBytes of srcMap = ht of destMap)
  30.     lsl.w    #3,d1                ; multiply by 8 to get ht of destMap when rot'd
  31.     mulu.w    d7,d1                ; multiply by rowbytes(destMap) = #words in
  32.     sub.w    d7,d1                ; destMap less one row
  33.     add.l    a3,d1                ; add the computed offset to the baseAddr of destMap
  34.     move.l    d1,lowerLeft-localVars(a0)    ; init lowerLeft
  35. ;
  36. ;-------------------------------------------------------------------------------
  37. ;    a0 = baseAddr for our locals        |    d0 = rowbytes of srcMap
  38. ;    a1 = points to bits of src bitMap    |    d1 = SCRATCH
  39. ;    a2 = SCRATCH                        |    d2 = colmCounter
  40. ;    a3 = dest bits                        |    d3 = current srcMap word 
  41. ;    a4 = SCRATCH                        |    d4 = colmBitLoop counter
  42. ;    a5 = not used                        |    d5 = current word destMap
  43. ;    a6 = not used                        |    d6 = insideLoop count (current bit)
  44. ;    a7 = not used                        |    d7 = rowBytes of dest bitMap
  45. ;-------------------------------------------------------------------------------
  46. ;
  47.  
  48. ;    _Debugger;
  49.     
  50. ; init wordCount to zero 
  51. ;
  52.     move.w    #0,wordCount-localVars(a0)    ; set wordCount to one before we start
  53. ;
  54. ; init colmLoop counter
  55. ;
  56.     move.w    d7,d2                ; get rowBytes(dest)
  57.     lsr        #1,d2                ; divide by 2 - d2 now contains the outer counter
  58.     move.w    d2,colmCount-localVars(a0)    ; put the max value away for reference
  59.     moveq.l    #0,d2                ; set d2 to zero since we use it for the counter
  60.  
  61. colmLoop
  62. ;
  63. ; this is the outside loop
  64. ;
  65.     move.w    #15,d4                ; init colmBitLoop counter to 15
  66.     move.l    lowerLeft-localVars(a0), a2    ; init currentWord    
  67.  
  68. colmBitLoop
  69. ;
  70. ; this is the loop that does the bit counting in the destMap - it is really a
  71. ; misuse of the 'dbra' instruction since it is not an independent loop but it
  72. ; is a quite cheap method of doing our counting
  73. ;
  74.  
  75.     cmp.w    #7, d4                        ; are we doing high byte or low?
  76.     bgt        dobyte1                        ; skip if high byte
  77.     addq    #1, a2                        ; else point to low byte
  78. dobyte1
  79.  
  80. rowLoop
  81. ;
  82. ; loop across each row in the srcMap and keep count each time we do a row
  83. ; this 'rowCount' will used to compute the offset from 'lowerLeft'
  84. ;
  85.     move.w    (a1)+, d3                    ; get a word to rotate into d3
  86.     addq.w    #2,wordCount-localVars(a0)    ; add 1 for each word •••jdo•••
  87.     
  88.     add.w    d3, d3                        ; test next bit in the current source word
  89.     bcc.s    NoBitToChange                ; if bit’s not set, skip to next
  90.     bset    d4, (a2)                    ; set proper bit in high or low byte in currentWord
  91. noBitToChange
  92.     sub.l    d7, a2                        ; subtract rowBytes(destMap) from current word
  93.  
  94.     ; Do the same as above, fifteen more times.
  95.     add.w    d3, d3
  96.     bcc.s    @1
  97.     bset    d4, (a2)
  98. @1    sub.l    d7, a2
  99.  
  100.     add.w    d3, d3
  101.     bcc.s    @2
  102.     bset    d4, (a2)
  103. @2    sub.l    d7, a2
  104.  
  105.     add.w    d3, d3
  106.     bcc.s    @3
  107.     bset    d4, (a2)
  108. @3    sub.l    d7, a2
  109.  
  110.     add.w    d3, d3
  111.     bcc.s    @4
  112.     bset    d4, (a2)
  113. @4    sub.l    d7, a2
  114.  
  115.     add.w    d3, d3
  116.     bcc.s    @5
  117.     bset    d4, (a2)
  118. @5    sub.l    d7, a2
  119.  
  120.     add.w    d3, d3
  121.     bcc.s    @6
  122.     bset    d4, (a2)
  123. @6    sub.l    d7, a2
  124.  
  125.     add.w    d3, d3
  126.     bcc.s    @7
  127.     bset    d4, (a2)
  128. @7    sub.l    d7, a2
  129.  
  130.     add.w    d3, d3
  131.     bcc.s    @8
  132.     bset    d4, (a2)
  133. @8    sub.l    d7, a2
  134.  
  135.     add.w    d3, d3
  136.     bcc.s    @9
  137.     bset    d4, (a2)
  138. @9    sub.l    d7, a2
  139.  
  140.     add.w    d3, d3
  141.     bcc.s    @10
  142.     bset    d4, (a2)
  143. @10    sub.l    d7, a2
  144.  
  145.     add.w    d3, d3
  146.     bcc.s    @11
  147.     bset    d4, (a2)
  148. @11    sub.l    d7, a2
  149.  
  150.     add.w    d3, d3
  151.     bcc.s    @12
  152.     bset    d4, (a2)
  153. @12    sub.l    d7, a2
  154.  
  155.     add.w    d3, d3
  156.     bcc.s    @13
  157.     bset    d4, (a2)
  158. @13    sub.l    d7, a2
  159.  
  160.     add.w    d3, d3
  161.     bcc.s    @14
  162.     bset    d4, (a2)
  163. @14    sub.l    d7, a2
  164.  
  165.     add.w    d3, d3
  166.     bcc.s    @15
  167.     bset    d4, (a2)
  168. @15    sub.l    d7, a2
  169.  
  170. ;
  171. ; at this point we've just completed a word from the srcMap
  172. ;
  173.     cmp        wordCount-localVars(a0),d0        ; cmp wordCount to rowBytes-are we done with a row ?
  174.     bne        rowLoop                            ; no - do another word
  175.     
  176.     cmp.w    #7, d4                        ; did we do high byte or low?
  177.     bgt        dobyte2                        ; skip if high byte
  178.     subq    #1, a2                        ; else undo the fudge to a2
  179. dobyte2
  180.  
  181. ;
  182. ; we just completed a row so add 2 to the count
  183. ;
  184.     move.w    #0,wordCount-localVars(a0)        ; •••jdo••• reset wordCount to zero
  185.  
  186. ;    
  187. ; the following use of dbra keeps track of our destMap bit for us
  188. ;
  189.     move.l    lowerLeft-localVars(a0), a2    ; re-init currentWord    
  190.                                         ; set the currentWord to the lowerLeft(current)
  191.                                         ; lowerLeft is moved over (right) by a word each
  192.                                         ; time we do a row in the srcMap
  193.     dbra    d4,colmBitLoop                ; go thru the bits (15->0) in the
  194.                                         ; destMap - then exit and do it
  195.                                         ; again for rowBytes/2 times
  196.  
  197. ;
  198. ; were done counting thru the bits of a destMap word - at this point we have
  199. ; actually finished a column in the destMap. The column is a multiple of
  200. ; 16 bits wide (and being at least 1 colm) and as tall as the destMap is
  201. ; (which is also equal to rowBytes of the srcMap)
  202. ;
  203.     addq.l    #2,lowerLeft-localVars(a0)        ; this moves us into the next
  204.                                             ; 'column' of bits in the destMap
  205.     addq.w    #1,d2                            ; add 1 to the colmLoop counter
  206.     cmp        colmCount-localVars(a0),d2        ; are we done yet ?
  207.     bne        colmLoop                        ; no - do it again
  208.                                             ; else we're done
  209. ;
  210. ; were done so lets do our clean-up/restore and go away gracefully
  211. ;
  212.     move.l    ticks, d0            ; get the current time…
  213.     sub.l    startTime-localVars(a0), d0 ; …less starting time
  214.     _Debugger                    ; and let me see the time it took
  215.  
  216.     movem.l    (sp)+,d3-d7/a2-a5    ; restore registers
  217.     unlk    a6                    ; clean up stack frame
  218.     move.l    (sp)+,a0            ; return address
  219.     add.l    #8,sp                ; pop parameters off stack
  220.     jmp        (a0)                 ; bye y'all!
  221.     
  222. ;
  223. ; set up our data storage area
  224. ;
  225. localVars                        ; the beginning of our local var storage area
  226. colmCount        ds.w    1
  227. currentWord        ds.l    1
  228. lowerLeft        ds.l    1
  229. wordCount        ds.w    1
  230. startTime        ds.l    1
  231.  
  232.     ENDP
  233.     
  234.     END
  235.     
  236.  
  237.